import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import ElementTest from '../views/elementtest.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', meta: { title: '登录' }, name: 'Login', component: () => import('../views/Login.vue') },
    { path: '/register', meta: { title: '注册' }, name: 'Register', component: () => import('../views/Register.vue') },
    { path: '/manager', redirect: '/manager/element', component: () => import('../views/Manager.vue'), children: [
        { path: 'home', meta: { title: '首页' }, name: 'Home', component: HomeView },
        { path: 'element', meta: { title: 'element测试' }, name: 'Element', component: ElementTest },
        { path: 'employee', meta: { title: '员工信息' }, name: 'Employee', component: () => import('../views/Employee.vue') },
        { path: 'admin', meta: { title: '管理员信息' }, name: 'Admin', component: () => import('../views/Admin.vue') },
        { path: 'person', meta: { title: '个人信息' }, name: 'Person', component: () => import('../views/Person.vue') },
        { path: 'password', meta: { title: '修改密码' }, name: 'Password', component: () => import('../views/Password.vue') },
        { path: 'article', meta: { title: '文章管理' }, name: 'Article', component: () => import('../views/Article.vue') },
        { path: 'department', meta: { title: '部门管理' }, name: 'Department', component: () => import('../views/Department.vue') },
        { path: 'data', meta: { title: '数据统计' }, name: 'Data', component: () => import('../views/Data.vue') }
    ]},
    { path: '/404', meta: { title: '404找不到页面' }, name: '404找不到页面', component: () => import('../views/404.vue') },
    { path: '/:pathMatch(.*)*', redirect: '/404' }
  ]
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title || '我的Vue项目'
  next()
})

export default router
